package com.yxd.demo.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Objects;


/**
 * @author: yxd
 * @date: 2022/8/1 14:54
 */
@Service
@Slf4j
public class MarketingWayService {
    public static void present(Long id, String type, Long userId) {
        log.info("为当前用户：{},赠送一张类型为：{},id为：{}的优惠", userId, type, id);
    }

    public static BigDecimal subtract(BigDecimal totalPrice, BigDecimal cutPrice) {
        if (totalPrice == null) {
            totalPrice = new BigDecimal(0);
        }
        if (cutPrice == null) {
            cutPrice = new BigDecimal(0);
        }
        return totalPrice.subtract(cutPrice);
    }

    public static BigDecimal multiply(BigDecimal totalPrice, BigDecimal discount) {
        if (totalPrice == null) {
            totalPrice = new BigDecimal(0);
        }
        if (discount == null) {
            discount = new BigDecimal(0);
        }
        return totalPrice.multiply(discount).setScale(2, RoundingMode.HALF_UP);
    }

    public static boolean compareTo(BigDecimal var1, BigDecimal var2){
        if (var1 == null) {
            var1 = new BigDecimal(0);
        }
        if (var2 == null) {
            var2 = new BigDecimal(0);
        }
        return !Objects.equals(-1, var1.compareTo(var2));
    }

    public static BigDecimal add(BigDecimal var1, BigDecimal var2) {
        if (var1 == null) {
            var1 = new BigDecimal(0);
        }
        if (var2 == null) {
            var2 = new BigDecimal(0);
        }
        return var1.add(var2);
    }
}
